<!-- $Id: brand_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>ECSHOP 管理中心 - 添加商品 </title>
        <meta name="robots" content="noindex, nofollow"/>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="__CSS__/general.css" rel="stylesheet" type="text/css" />
        <link href="__CSS__/main.css" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" href="__ZTREE__/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
        <css href='__UPLOADIFY__/common.css'/>
        <style type="text/css">
            .gallery-upload-pre-item img{
                width:100px;
            }

            .gallery-upload-pre-item{
                display:inline-block;
            }

            .gallery-upload-pre-item a{
                position:relative;
                top:5px;
                right:15px;
                float:right;
                color:red;
                font-size:16px;
                text-decoration:none;
            }

            ul.ztree{
                margin-top: 10px;
                border: 1px solid #617775;
                background: #f0f6e4;
                width: 220px;
                overflow-y: scroll;
                overflow-x: auto;
            }

        </style>
    </head>
    <body>
        <h1>
            <span class="action-span"><a href="{:U('index')}">商品商品</a></span>
            <span class="action-span1"><a href="#">ECSHOP 管理中心</a></span>
            <span id="search_id" class="action-span1"> - 添加商品 </span>
        </h1>
        <div style="clear:both"></div>
        <div class="tab-div">
            <div id="tabbar-div">
                <p>
                    <span class="tab-front" id="general-tab">通用信息</span>
                </p>
            </div>
            <div id="tabbody-div">
                <form enctype="multipart/form-data" action="{:U()}" method="post">
                    <table width="90%" id="general-table" align="center">
                        <tr>
                            <td class="label">商品名称：</td>
                            <td><input type="text" name="name" value="{$row.name}" size="30" />
                                <span class="require-field">*</span></td>
                        </tr>
                        <tr>
                            <td class="label">商品货号： </td>
                            <td>
                                <input type="text" name="sn" value="{$row.sn}" size="20" id="sn"/>
                                <span id="goods_sn_notice"></span><br />
                                <span class="notice-span"id="noticeGoodsSN">如果您不输入商品货号，系统将自动生成一个唯一的货号。</span>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">商品分类：</td>
                            <td>
                                <input type="hidden" name="goods_category_id" id='parent_id'/>
                                <input type='text' disabled='disabled' id='parent_name' style="padding-left:1em;"/>
                                <span class="require-field">*</span>
                                <ul id="goods_categories" class="ztree"></ul>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">商品品牌：</td>
                            <td>
                                <select name="brand_id">
                                    <option value="0">请选择...</option>
                                    <foreach name="brands" item="brand">
                                        <option value="{$brand['id']}" <if condition="$brand['id'] eq $row['brand_id']">selected='selected'</if>>{$brand.name}</option>
                                    </foreach>
                                </select>
                                <span class="require-field">*</span>
                            </td>
                        </tr>

                        <tr>
                            <td class="label">供货商：</td>
                            <td>
                                <select name="supplier_id">
                                    <option value="0">请选择...</option>
                                    <foreach name="suppliers" item="supplier">
                                        <option value="{$supplier['id']}" <if condition="$supplier['id'] eq $row['supplier_id']">selected='selected'</if> >{$supplier.name}</option>
                                    </foreach>
                                </select>
                                <span class="require-field">*</span>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">本店售价：</td>
                            <td>
                                <input type="text" name="shop_price" value="{$row.shop_price}" size="20"/>
                                <span class="require-field">*</span>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">市场售价：</td>
                            <td>
                                <input type="text" name="market_price" value="{$row.market_price}" size="20" />
                                <span class="require-field">*</span>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">商品数量：</td>
                            <td>
                                <input type="text" name="stock" size="8" value="{$row.stock}"/>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">是否上架：</td>
                            <td>
                                <input class="is_on_sale" type="radio" name="is_on_sale" value="1"/> 是
                                <input class="is_on_sale" type="radio" name="is_on_sale" value="0"/> 否
                            </td>
                        </tr>
                        <tr>
                            <td class="label">加入推荐：</td>
                            <td>
                                <input class="goods_status" type="checkbox" name="goods_status[]" value="1" /> 精品
                                <input class="goods_status" type="checkbox" name="goods_status[]" value="2" /> 新品
                                <input class="goods_status" type="checkbox" name="goods_status[]" value="4" /> 热销
                            </td>
                        </tr>
                        <tr>
                            <td class="label">推荐排序：</td>
                            <td>
                                <input type="text" name="sort" size="5" value="50"/>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">商品简单描述：</td>
                            <td>
                                <textarea id="editor" name="content">
                                    {$row.content}
                                </textarea>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">商品图片：</td>
                            <td>
                                <div class="gallery-upload-img-box">
                                    <foreach name="row.galleries" item="gallery">
                                        <div class="gallery-upload-pre-item">
                                            <img src="{$gallery}"/>
                                            <input type="hidden" name="path[]" value="{$gallery}">
                                            <a href="#" data="{$key}">×</a>
                                        </div>
                                    </foreach>
                                </div>
                                <div>
                                    <input type="file" id="goods_gallery"/>
                                </div>
                            </td>
                        </tr>
                    </table>
                    <div class="button-div">
                        <input type="hidden" name="id" value="{$row['id']}">
                        <input type="submit" value=" 确定 " class="button"/>
                        <input type="reset" value=" 重置 " class="button" />
                    </div>
                </form>
            </div>
        </div>

        <div id="footer">
            共执行 1 个查询，用时 0.018952 秒，Gzip 已禁用，内存占用 2.197 MB<br />
            版权所有 &copy; 2005-2012 上海商派网络科技有限公司，并保留所有权利。
        </div>
        <js href='__JS__/jquery.min.js'/>
        <script type="text/javascript" src="__ZTREE__/js/jquery.ztree.core.js"></script>
        <script type="text/javascript" src="__UEDITOR__/ueditor.config.js"></script>
        <script type="text/javascript" src="__UEDITOR__/ueditor.all.min.js"></script>
        <script type="text/javascript" src="__UEDITOR__/lang/zh-cn/zh-cn.js"></script>

        <js href='__UPLOADIFY__/jquery.uploadify.min.js'/>
        <js href='__LAYER__/layer.js'/>
        <script type='text/javascript'>
            //1...实例化编辑器
            var ue = UE.getEditor('editor');
            //-------------------- 编辑器结束--------------------
            var setting = {
                data: {
                    simpleData: {
                        enable: true,
                        pIdKey: 'parent_id',
                    },
                },
                callback:{
                    onClick:function(event,node,item){
                        //取出点击节点的数据，放到表单节点中
                        $('#parent_id').val(item.id);
                        $('#parent_name').val(item.name);
                    },
                },
            };

            var goods_categories = {$goods_categories};
            $(function () {
                //回显商品状态
                $('.status').val([{$row.status|default=1}]);
                //初始化ztree插件
                var goods_category_ztree = $.fn.zTree.init($("#goods_categories"), setting, goods_categories);
                //展开所有的节点
                goods_category_ztree.expandAll(true);

                //编辑页面回显父级分类
                <present name="row">
                    //获取父级分类在ztree中的节点
                    var parent_node = goods_category_ztree.getNodeByParam('id',{$row.goods_category_id});
                    goods_category_ztree.selectNode(parent_node);
                    $('#parent_id').val(parent_node.id);
                    $('#parent_name').val(parent_node.name);
                    $('#sn').attr('disabled',true);
                    $('.goods_status').val({$row['goods_status']});
                    $('.is_on_sale').val([{$row['status']|default=1}]);
                </present>
            });
            //----------------------ztree结束---------------------
            //使用uploadify初始化logo文件框

            $options = {
                swf:'__UPLOADIFY__/uploadify.swf',
                uploader:'{:U("Upload/uploadImg")}',
                buttonText:' 选择文件 ',
                fileObjName:'file_data',
                onUploadSuccess:function(file_item,response){
                    //根据返回的status来判定是否成功
                    var data = $.parseJSON(response);
                    if(data.status){
                        var html = '<div class="gallery-upload-pre-item">\
                                        <img src="'+data.file_url+'"/>\
                                        <a href="#">×</a>\
                                        <input type="hidden" name="path[]" value="'+data.file_url+'"/>\
                                    </div>';
                        $(html).appendTo($('.gallery-upload-img-box'));
                        layer.alert(data.msg, {icon: 6});
                    }else{
                        layer.alert(data.msg, {icon: 5});
                    }
                },
            };
            $('#goods_gallery').uploadify($options);
            //--------------------------------上传图片结束-----------------
            //---------------------------------ajax删除相册
            $('.gallery-upload-img-box').on('click','a',function(){
                var id=$(this).attr('data');
                var flag=true;
                var parentNode=$(this).parent();
                if(id){ //存在id删除数据库
                    //alert(22);
                    var url="{:U('Goods/removeGallery')}";
                    var data={
                        id:id
                    };
                    $.getJSON(url,data,function(response){
                        //console.debug(response);
                        if(!response.status){
                            flag=false;
                        }
                    });
                }

                if(flag){
                    //alert(33);
                    parentNode.remove();
                    layer.alert('删除成功', {icon: 6});
                }else {
                    layer.alert('删除失败', {icon: 5});
                }
                return false;
            });

        </script>
    </body>
</html>